﻿import cTitle from "components/title";
import shareCode from "./components/shareCode.vue"
import lucencyPop from "./components/lucencyPop.vue"
export default {
  data() {
    return {
      showShare: false,
      item: '',
      mark_id: '',
      getSucceed: false,
      new_coupon:false
    };
  },
  methods: {
    goConponCenter() {
      this.$router.push(this.fun.getUrl("couponStore", { info: this.info }));
    },
    goMyCoupon() {
      this.$router.push(this.fun.getUrl("coupon", {}));
    },
    lucencyClose() {
      this.getSucceed = false;
    },
    getData() {
      var that = this;
      let urlStr = "plugin.share-coupons.Frontend.controllers.share.index";
      if(this.$route.name == 'new_CouponShareGet'){
        urlStr = "plugin.new-coupon.frontend.controllers.share-coupon.index"
      }
      $http.post(urlStr, { mark_id: that.mark_id }).then(
        response => {
          if (response.result === 1) {
            this.item = response.data;
          } else {
						this.$toast(response.msg);
            if (!this.fun.isTextEmpty(response.data)) {
              if (response.data.used == '1') {
                this.$toast('优惠券已被领取完');
                this.$router.push(this.fun.getUrl("coupon", {}));
              }
            }
          }
        },
        function (response) {
          console.log(response);
        }
      );
    },
    tapGet() {
      let urlStr = "plugin.share-coupons.Frontend.controllers.share.handle";
      if(this.$route.name == 'new_CouponShareGet'){
        urlStr = "plugin.new-coupon.frontend.controllers.share-coupon.receive"
      }
      $http.post(urlStr, { mark_id: this.mark_id }).then(
        response => {
          if (response.result === 1) {
            this.getSucceed = true;
          } else {
            this.$dialog.alert({message:response.msg});
           
          }
        },
        function (response) {
          console.log(response);
        }
      );
    }
  },
  activated() {
    this.mark_id = this.$route.query.mark_id;
    if(this.$route.name == 'new_CouponShareGet'){
      this.new_coupon = true;
    }
    this.getData();
  },
  mounted() { },
  components: { 
    cTitle,
    shareCode,
    lucencyPop
  }
};